package edu.hawaii.myisern.action;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;

/**
 * Handles the logging out functionality of the MyIsern 2.0 website.
 * Code attributed to Jon Lao's discussion post on logging out on the
 * Fall 2007 ICS 413 google website.
 * @author Sonwright M. Gomez
 *
 */
public class LogoutActionBean extends MyIsernActionBean {

  /** An error string, always displayed, but invisible if empty. */
  private String errorMessage = "";
  
  /**
   * Returns the error message, which may be empty.
   * Indicates if someone tried to pop an empty stack. 
   * @return The error message. 
   */
  public String getErrorMessage() {
    return this.errorMessage;
  }
  
  /**
   * Set's the error message for the user.
   * 
   * @param errorMessage containing error Message. 
   */
  public void setErrorMessage(String errorMessage) {
    this.errorMessage = errorMessage;
  }
  
  /**
   * Handles the logout request from the user.  It invalidates
   * the current session and redirects the user to the index/login
   * homepage.
   * @return Resolution to display the index homepage.
   */
  @DefaultHandler
  public Resolution logout() {
    getContext().getRequest().getSession().invalidate();
    return new RedirectResolution("/index.jsp"); 
  }
}
